﻿@{
    ViewBag.Title = "保存模型配置";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@model  Model.ModelConfig
<style>
    .searchArea
    {
        line-height: 20px;
    }
    .pagTable td
    {
        padding-left: 5px;
    }
</style>
<script type="text/javascript">
    var UrlArray = $.getUrlArray();
    $(function () {
        $("#link a").each(function () {
            $(this).attr("href", $(this).attr("href") + "?modelID=" + UrlArray["modelID"] + "&dbName=" + encodeURI(UrlArray["dbName"])
            + "&nmID=" + UrlArray["nmID"] + "&ndbName=" + encodeURI(UrlArray["ndbName"]));
        });
    });
    function back() {
        window.location = "/ModelConfig/ExtendEdit?modelID=" + UrlArray["modelID"] + "&dbName=" + encodeURI(UrlArray["dbName"])
         + "&nmID=" + UrlArray["nmID"] + "&ndbName=" + encodeURI(UrlArray["ndbName"]);
    }
    function goto(u) {
        window.location = u + "?modelID=" + UrlArray["modelID"] + "&dbName=" + encodeURI(UrlArray["dbName"])
         + "&nmID=" + UrlArray["nmID"] + "&ndbName=" + encodeURI(UrlArray["ndbName"]);
    }
    function save() {
        $("#msg").html("");
        var modelID = UrlArray["modelID"];
        var dbName = UrlArray["dbName"];
        if (UrlArray["nmID"] && UrlArray["nmID"] != "null") {
            modelID = UrlArray["nmID"];
            dbName = UrlArray["ndbName"];
        } 
        $("#loading").show();
        $.post("/ModelConfig/RunScript?modelID=" + modelID + "&dbName=" + encodeURI(dbName), function (result) {
            if (result == "6") {
                alert("执行成功！");
                window.location.reload();
            }
            else {
                switch (result) {
                    case 2:
                        $("#msg").html("填充数据源数据出错。");
                        break;
                    case 3:
                        $("#msg").html("创建Fact表出错。");
                        break;
                    case 5:
                        $("#msg").html("创建视图出错，请检查扩展视图脚本设置。");
                        break;
                    default:
                        $("#msg").html(result);
                        break;
                }
            }
            $("#loading").hide();
        });
    }
</script>
<div style="margin: 5px;">
    <table class="listTitle" id="link">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="800">
                <a href="/ModelConfig/Index">模型管理</a> --> <a href="/ModelConfig/Edit">新增模型配置</a>
                --> <a href="/ODSConfig/ODSConfigAdd">选择源系统表</a> --> <a href="/DQConfig/Index">数据质量配置列表</a>
                --> <a href="/ModelConfig/EditColumn">模型字段配置</a> --> <a href="/ModelConfig/ExtendEdit">
                    模型扩展字段配置</a> --> 保存模型配置
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <table class="searchArea" width="100%">
        <tr>
            <td style=" line-height:25px; padding-left:20px;">
                模型名称：@Model.TableName<br />
                模型描述：@Model.TableDescription<br />
            </td>
        </tr>
    </table>
    <table class="listTitle" id="link">
        <tr>
            <td width="15">
                <img src="/images/edit.png" />
            </td>
            <td width="200">
                模型创建状态
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    @if (Model.Step == 6)
    {
        <table class="pagTable" cellpadding="0" cellspacing="0">
            <tr class='pagTablehd'>
                <td width="150">
                    步骤名称
                </td>
                <td align="center" width="150">
                    创建状态
                </td>
                <td>
                    操作
                </td>
            </tr>
            <tr>
                <td width="150">
                    1.保存模型信息.
                </td>
                <td width="100" align="center">
                    <
                    <img src="/images/tree_dnd_yes.png" title="已完成" />
                    >
                </td>
                <td>
                    <a href="#" onclick="goto('/ModelConfig/Edit')">进入编辑</a>
                </td>
            </tr>
            <tr>
                <td>
                    2.保存数据源表.
                </td>
                <td align="center">
                    <
                    <img src="/images/tree_dnd_yes.png" title="已完成" />
                    >
                </td>
                <td>
                    <a href="#" onclick="goto('/ODSConfig/ODSConfigAdd')">进入编辑</a>
                </td>
            </tr>
            <tr>
                <td>
                    3.保存数据质量.
                </td>
                <td align="center">
                    <
                    <img src="/images/tree_dnd_yes.png" title="已完成" />
                    >
                </td>
                <td>
                    <a href="#" onclick="goto('/DQConfig/Index')">进入编辑</a>
                </td>
            </tr>
            <tr>
                <td>
                    4.保存模型字段.
                </td>
                <td align="center">
                    <
                    <img src="/images/tree_dnd_yes.png" title="已完成" />
                    >
                </td>
                <td>
                    <a href="#" onclick="goto('/ModelConfig/EditColumn')">进入编辑</a>
                </td>
            </tr>
            <tr>
                <td>
                    5.保存模型扩展字段.
                </td>
                <td align="center">
                    <
                    <img src="/images/tree_dnd_yes.png" title="已完成" />
                    >
                </td>
                <td>
                    <a href="#" onclick="goto('/ModelConfig/ExtendEdit')">进入编辑</a>
                </td>
            </tr>
        </table>
    }
    else
    {
        <table class="pagTable" cellpadding="0" cellspacing="0">
            <tr class='pagTablehd'>
                <td width="150">
                    步骤名称
                </td>
                <td align="center" width="150">
                    创建状态
                </td>
                <td>
                    操作
                </td>
            </tr>
            <tr>
                <td width="150">
                    1.保存模型信息.
                </td>
                <td width="100" align="center">
                    <span class="resultTeg">
                        <已保存>
                    </span>
                </td>
                <td>
                    <a href="#" onclick="goto('/ModelConfig/Edit')">进入编辑</a>
                </td>
            </tr>
            <tr>
                <td>
                    2.保存数据源表.
                </td>
                <td align="center">
                    <span class="resultTeg">@(Model.Step >= 2 ? "<已保存>" : "<未保存>")</span>
                </td>
                <td>
                    <a href="#" onclick="goto('/ODSConfig/ODSConfigAdd')">进入编辑</a>
                </td>
            </tr>
            <tr>
                <td>
                    3.保存数据质量.
                </td>
                <td align="center">
                    <span class="resultTeg">@(Model.Step >= 3 ? "<已保存>" : "<未保存>")</span>
                </td>
                <td>
                    <a href="#" onclick="goto('/DQConfig/Index')">进入编辑</a>
                </td>
            </tr>
            <tr>
                <td>
                    4.保存模型字段.
                </td>
                <td align="center">
                    <span class="resultTeg">@(Model.Step >= 4 ? "<已保存>" : "<未保存>")</span>
                </td>
                <td>
                    <a href="#" onclick="goto('/ModelConfig/EditColumn')">进入编辑</a>
                </td>
            </tr>
            <tr>
                <td>
                    5.保存模型扩展字段.
                </td>
                <td align="center">
                    <span class="resultTeg">@(Model.Step >= 5 ? "<已保存>" : "<未保存>")</span>
                </td>
                <td>
                    <a href="#" onclick="goto('/ModelConfig/ExtendEdit')">进入编辑</a>
                </td>
            </tr>
        </table>
    }
    <br />
    <input type="button" class="button" value="上一步" onclick="back()" />
    <input type="button" class="button" value="立即执行" onclick="save()" @(Model.Step >= 5 ? "" : "disabled='disabled'") />
    <div id="loading" class="loading">
        <img src="/Images/tree_loading.gif" />
    </div>
    <div id="msg">
    </div>
</div>
